#include "myiic.h"

#define I2C1_SPEED 100000
#define I2C1_SLAVE_ADDRESS7 0xA0

void I2C1_Init(void)
{
    //GPIO Init
    rcu_periph_clock_enable(RCU_GPIOB);/* enable GPIOB clock */
    gpio_init(GPIOB, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_10 | GPIO_PIN_11);/* connect PB10 to I2C1_SCL  connect PB11 to I2C1_SDA */
    //i2c1 init
    
    rcu_periph_clock_enable(RCU_I2C1);/* enable I2C clock */
    i2c_clock_config(I2C1, I2C1_SPEED, I2C_DTCY_2);/* configure I2C clock */
    
    i2c_mode_addr_config(I2C1, I2C_I2CMODE_ENABLE, I2C_ADDFORMAT_7BITS, I2C1_SLAVE_ADDRESS7);/* configure I2C address */
    i2c_enable(I2C1);/* enable I2C1 */
    i2c_ack_config(I2C1, I2C_ACK_ENABLE);/* enable acknowledge */
}
